<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>获取一个配置选项的值</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.ini-get-all.html">ini_get_all</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.ini-restore.html">ini_restore</a></div>
 <div class="up"><a href="ref.info.html">PHP 选项/信息 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.ini-get" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">ini_get</h1>
  <p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">ini_get</span> &mdash; <span class="dc-title">获取一个配置选项的值</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.ini-get-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">string</span> <span class="methodname"><strong>ini_get</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$varname</code></span>
   )</div>

  <p class="para rdfs-comment">
   成功时返回配置选项的值。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.ini-get-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<em><code class="parameter">varname</code></em></dt>

     <dd>

      <p class="para">
       配置选项名称。
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.ini-get-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   成功是返回配置选项值的字符串，<em>null</em> 的值则返回空字符串。如果配置选项不存在，将会返回 <strong><code>FALSE</code></strong>。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.ini-get-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-475">
    <p><strong>Example #1 一些 <span class="function"><strong>ini_get()</strong></span> 例子</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">/*<br />我们的&nbsp;php.ini&nbsp;包含了以下的设置：<br /><br />display_errors&nbsp;=&nbsp;On<br />register_globals&nbsp;=&nbsp;Off<br />post_max_size&nbsp;=&nbsp;8M<br />*/<br /><br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #DD0000">'display_errors&nbsp;=&nbsp;'&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">ini_get</span><span style="color: #007700">(</span><span style="color: #DD0000">'display_errors'</span><span style="color: #007700">)&nbsp;.&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />echo&nbsp;</span><span style="color: #DD0000">'register_globals&nbsp;=&nbsp;'&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">ini_get</span><span style="color: #007700">(</span><span style="color: #DD0000">'register_globals'</span><span style="color: #007700">)&nbsp;.&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />echo&nbsp;</span><span style="color: #DD0000">'post_max_size&nbsp;=&nbsp;'&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">ini_get</span><span style="color: #007700">(</span><span style="color: #DD0000">'post_max_size'</span><span style="color: #007700">)&nbsp;.&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />echo&nbsp;</span><span style="color: #DD0000">'post_max_size+1&nbsp;=&nbsp;'&nbsp;</span><span style="color: #007700">.&nbsp;(</span><span style="color: #0000BB">ini_get</span><span style="color: #007700">(</span><span style="color: #DD0000">'post_max_size'</span><span style="color: #007700">)+</span><span style="color: #0000BB">1</span><span style="color: #007700">)&nbsp;.&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />echo&nbsp;</span><span style="color: #DD0000">'post_max_size&nbsp;in&nbsp;bytes&nbsp;=&nbsp;'&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">return_bytes</span><span style="color: #007700">(</span><span style="color: #0000BB">ini_get</span><span style="color: #007700">(</span><span style="color: #DD0000">'post_max_size'</span><span style="color: #007700">));<br /><br />function&nbsp;</span><span style="color: #0000BB">return_bytes</span><span style="color: #007700">(</span><span style="color: #0000BB">$val</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$val&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">trim</span><span style="color: #007700">(</span><span style="color: #0000BB">$val</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$last&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">strtolower</span><span style="color: #007700">(</span><span style="color: #0000BB">$val</span><span style="color: #007700">[</span><span style="color: #0000BB">strlen</span><span style="color: #007700">(</span><span style="color: #0000BB">$val</span><span style="color: #007700">)-</span><span style="color: #0000BB">1</span><span style="color: #007700">]);<br />&nbsp;&nbsp;&nbsp;&nbsp;switch(</span><span style="color: #0000BB">$last</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;自&nbsp;PHP&nbsp;5.1.0&nbsp;起可以使用修饰符&nbsp;'G'<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">case&nbsp;</span><span style="color: #DD0000">'g'</span><span style="color: #007700">:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$val&nbsp;</span><span style="color: #007700">*=&nbsp;</span><span style="color: #0000BB">1024</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;</span><span style="color: #DD0000">'m'</span><span style="color: #007700">:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$val&nbsp;</span><span style="color: #007700">*=&nbsp;</span><span style="color: #0000BB">1024</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;</span><span style="color: #DD0000">'k'</span><span style="color: #007700">:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$val&nbsp;</span><span style="color: #007700">*=&nbsp;</span><span style="color: #0000BB">1024</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;</span><span style="color: #0000BB">$val</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程的输出类似于：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>

display_errors = 1
register_globals = 0
post_max_size = 8M
post_max_size+1 = 9
post_max_size in bytes = 8388608

</pre></div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.ini-get-notes">
  <h3 class="title">注释</h3>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <strong>当查询一个 boolean 值</strong><br />
   <p class="para">
    一个 <em>off</em> 的 boolean ini 值将会以空字符串或者 &quot;0&quot; 返回；<em>on</em> 的 ini 值会以 &quot;1&quot; 返回。
    此函数也会返回 INI 值的文字字符串。
   </p>
  </p></blockquote>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <strong>当查询一个内存尺寸的值</strong><br />
   <p class="para">
    许多内存尺寸的 ini 值，类似 <a href="ini.core.html#ini.upload-max-filesize" class="link">upload_max_filesize</a> 是以简写表示法储存在 <var class="filename">php.ini</var> 文件里。
    <span class="function"><strong>ini_get()</strong></span> 会返回 <var class="filename">php.ini</var> 文件中储存的确切字符串，而<em class="emphasis">不是</em>它的等量 <span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span>。
    尝试对这些值使用常规算术运算函数将不会得到预期的结果。
    以上例子显示了转换简写表示法为字节的一种方式，和 PHP 源码所做的比较像。
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.ini-get-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.get-cfg-var.html" class="function" rel="rdfs-seeAlso">get_cfg_var()</a> - 获取 PHP 配置选项的值</span></li>
    <li class="member"><span class="function"><a href="function.ini-get-all.html" class="function" rel="rdfs-seeAlso">ini_get_all()</a> - 获取所有配置选项</span></li>
    <li class="member"><span class="function"><a href="function.ini-restore.html" class="function" rel="rdfs-seeAlso">ini_restore()</a> - 恢复配置选项的值</span></li>
    <li class="member"><span class="function"><a href="function.ini-set.html" class="function" rel="rdfs-seeAlso">ini_set()</a> - 为一个配置选项设置值</span></li>
   </ul>
  </p>
 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.ini-get-all.html">ini_get_all</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.ini-restore.html">ini_restore</a></div>
 <div class="up"><a href="ref.info.html">PHP 选项/信息 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
